package com.ruoyi.web.controller.biz;

import java.util.List;

import com.ruoyi.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.biz.domain.BizCourseCredit;
import com.ruoyi.biz.service.IBizCourseCreditService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学分记录Controller
 * 
 * @author ruoyi
 * @date 2021-09-01
 */
@Controller
@RequestMapping("/biz/credit")
public class BizCourseCreditController extends BaseController
{
    private String prefix = "biz/credit";

    @Autowired
    private IBizCourseCreditService bizCourseCreditService;

    @RequiresPermissions("biz:credit:view")
    @GetMapping()
    public String credit()
    {
        return prefix + "/credit";
    }

    /**
     * 查询学分记录列表
     */
    @RequiresPermissions("biz:credit:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizCourseCredit bizCourseCredit)
    {
        startPage();
        Long                  userId = ShiroUtils.getUserId();
        bizCourseCredit.setUserId(userId.intValue());
        List<BizCourseCredit> list = bizCourseCreditService.selectBizCourseCreditList(bizCourseCredit);
        return getDataTable(list);
    }

    /**
     * 导出学分记录列表
     */
    @RequiresPermissions("biz:credit:export")
    @Log(title = "学分记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizCourseCredit bizCourseCredit)
    {
        List<BizCourseCredit> list = bizCourseCreditService.selectBizCourseCreditList(bizCourseCredit);
        ExcelUtil<BizCourseCredit> util = new ExcelUtil<BizCourseCredit>(BizCourseCredit.class);
        return util.exportExcel(list, "credit");
    }

    /**
     * 新增学分记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学分记录
     */
    @RequiresPermissions("biz:credit:add")
    @Log(title = "学分记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizCourseCredit bizCourseCredit)
    {
        return toAjax(bizCourseCreditService.insertBizCourseCredit(bizCourseCredit));
    }

    /**
     * 修改学分记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        BizCourseCredit bizCourseCredit = bizCourseCreditService.selectBizCourseCreditById(id);
        mmap.put("bizCourseCredit", bizCourseCredit);
        return prefix + "/edit";
    }

    /**
     * 修改保存学分记录
     */
    @RequiresPermissions("biz:credit:edit")
    @Log(title = "学分记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizCourseCredit bizCourseCredit)
    {
        return toAjax(bizCourseCreditService.updateBizCourseCredit(bizCourseCredit));
    }

    /**
     * 删除学分记录
     */
    @RequiresPermissions("biz:credit:remove")
    @Log(title = "学分记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bizCourseCreditService.deleteBizCourseCreditByIds(ids));
    }
}
